<?php
class Core_Component_Sef_Business_Rewrite_Flow_Route extends Core_Component_Sef_Business_Rewrite_Flow_Base{

	public function __construct(){}

	public function run(){
		$url = $_SERVER['REQUEST_URI'];
		$isHtml = Soul_Util_String::endsWith($url, '.html');
		$notDomain = !Soul_Config::getDomain($GLOBALS[RC]->getRequest()->getSubdomain());
		if($isHtml || $notDomain){
			$url = Soul_Util_String::subString($url, '.').'/';
			if($url == '//'){
				$url = '/';
			}
			
			foreach($this->getRewriters() as $rewriter){
				$r = $rewriter->rewriteRoute($url);
				if($r !== FALSE){
					$_SERVER['REWRITE_URI'] = $_SERVER['REQUEST_URI'];
					$_SERVER['REWRITE_HOST'] = $_SERVER['HTTP_HOST'];
					$_SERVER['REQUEST_URI'] = $r['url'];
					$_SERVER['HTTP_HOST'] = $r['domain'].'.'.DN;
					return;
				}
			}
		}
	}
}